import api from "@/sdk/api/api.js"
export default {
	state:{
		tabList:[
			{
				type:"1",
				name:"储蓄卡",
				data:[
				]
			},
			{
				type:"2",
				name:"信用卡",
				data:[
					
				]
			}
		],
		bankList:[],
		has_bank:false,
		selectObj:null,
	},
	mutations:{
		changeTabList(state,tabList){
			console.log(tabList);
			state.tabList = tabList;
		},
		changeBankList(state,bankList){
			console.log(bankList);
			if(bankList&&bankList.length>0){
				state.has_bank = true;
				state.selectObj = bankList[0]
				console.log(state.selectObj);
			}
			state.bankList = bankList
		},
		changeCount(state,index){
			let banklist = state.bankList
			state.selectObj = banklist[index]
		}
	},
	actions:{
		//获取用户的卡
		async getUserCard(context){
			let tabList = context.state.tabList;
			let bankList = []
			for(var a in tabList){
				let res = await api.getUserCard({type:tabList[a].type})
				tabList[a].data = res;
				bankList.push(...res);
			}
			context.commit("changeTabList",tabList);
			context.commit("changeBankList",bankList)
		}
	}
}